<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'register.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<style type="text/css">
span {
	color: red;
	font: 10pt;
}

body {
	width: expression(body.clientWidth);
	height: expression(body.clientHeight);
	left: 0px;
	top: 0px;
	position: absolute;
	background: url("dwz/themes/default/images/top.gif");
}
</style>


<script type="text/javascript" src="dwz/js/jquery-1.7.2.js"></script>

<SCRIPT type="text/javascript">
        $(function($){
            $(".warns").hide();
        	var status0;
        	status0=$('#student').attr('value');
        	$('#student').bind("click",function(){
        		status0=$('#student').attr('value');
        	});
        	$('#teacher').bind("click",function(){
        		status0=$('#teacher').attr('value');
        	});
        	$('#register').bind("click",function(){
        		var b=userStatus();
                if(b==false){
                  return false;
                }
        		var url='register_UserInfo_ajax';
        		params={
        		    userId:$('#userId').attr('value'),
        			userName:$('#userName').attr('value'),
        			userPassword:$('#userPassword').attr('value'),
        			email:$('#email').attr('value'),
        			telephone:$('#telephone').attr('value'),
        			papersNum:$('#papersNum').attr('value'),
        			userStatus:status0
        		}
        	    $.post(url,params,callbackFunction,'json');
        		function callbackFunction(data){
        			alert(data.back);
        			if(data.back=="注册成功"){
        				window.location.href="index.jsp";
        			}
        		}
        	});
        	$('#back').bind("click",function(){
        		window.location.href="index.jsp";
        	});
    });   
       function userName(){
       var flag=true;
       $(function($){
        if($('#userId').attr('value')==""){
        	$("#userIdS1").show();
        	flag=false;
        }
        if($('#userId').attr('value')!=""){
        	$("#userIdS1").hide();
        	flag=true;
        	var r=/^\d+$/;
           if(!r.test($('#userId').attr('value'))){
    	    $("#userIdS2").show();
    	    flag=false;
           }
          if(r.test($('#userId').attr('value'))){
    	   $("#userIdS2").hide();
    	   flag=true;
           }
        }
      });
      return flag;
     } 
     function userPassword(){
       var flag=userName();
       $(function($){
        if($('#userName').attr('value')==""){
        	$("#userNameS1").show();
        	flag=false;
        }
        if($('#userName').attr('value')!=""){
        	$("#userNameS1").hide();
        	flag=true;
        }
      });
      return flag;
     } 
     function rnewPassword(){
     var flag=userPassword();
      $(function($){
        if($('#userPassword').attr('value')==""){
        	$("#userPasswordS1").show();
        	flag=false;
        }
        if($('#userPassword').attr('value')!=""){
        	$("#userPasswordS1").hide();
        	flag=true;
        }
      });
      return flag;
     }
     function email(){
     var flag=rnewPassword();
     $(function($){
        if($('#userPassword').attr('value')!=$('#rnewPassword').attr('value')){
        	$("#rnewPasswordS1").show();
        	flag=false;
        }
        if($('#userPassword').attr('value')==$('#rnewPassword').attr('value')){
        	$("#rnewPasswordS1").hide();
        	flag=true;
        }
      });
      return flag;
     }
     function telephone(){
     var flag=email();
     $(function($){
         if($('#email').attr('value')==""){
        	$("#emailS1").show();
        	flag=false;
        }
         if($('#email').attr('value')!=""){
        	$("#emailS1").hide();
        	flag=true;
            var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
            if(!reg.test($('#email').attr('value'))){
            $("#emailS2").show();
            flag=false;
            }
            if(reg.test($('#email').attr('value'))){
            $("#emailS2").hide();
            flag=true;
            }
        }
      });
      return flag;
     }
     
     function papersNum(){
     var flag=telephone();
     $(function($){
         if($('#telephone').attr('value')==""){
        	$("#telephoneS1").show();
        	flag=false;
        }
         if($('#telephone').attr('value')!=""){
        	$("#telephoneS1").hide();
        	flag=true;
            var reg = /^\d+$/;
            if(!reg.test($('#telephone').attr('value'))){
            $("#telephoneS2").show();
            flag=false;
            }
            if(reg.test($('#telephone').attr('value'))){
            $("#telephoneS2").hide();
            flag=true;
            }
        }
      });
     }
     function userStatus(){
     var flag=papersNum();
      $(function($){
         if($('#papersNum').attr('value')==""){
        	$("#papersNumS1").show();
        	flag=false;
        }
         if($('#papersNum').attr('value')!=""){
        	$("#papersNumS1").hide();
        	flag=true;
            var reg = /^\d+$/;
            if(!reg.test($('#papersNum').attr('value'))){
            $("#papersNumS2").show();
            flag=false;
            }
            if(reg.test($('#papersNum').attr('value'))){
            $("#papersNumS2").hide();
            flag=true;
            }
        }
      });
      return flag;
     }
      </script>
</head>

<body>

	<table width="40%" cellspacing="0" align="center" border="1">
		<tr>
			<td align="right">用户编号：</td>
			<td><input type="text" name="userId" id="userId" size="18" /><span
				class="warns" id="userIdS1">用户编号不能为空</span> <span class="warns"
				id="userIdS2">用户编号必须是数字</span></td>
		</tr>
		<tr>
			<td align="right">用户姓名：</td>
			<td><input type="text" name="userName" id="userName" size="18"
				onfocus="userName();" /> <span class="warns" id="userNameS1">用户姓名不能为空</span>
			</td>
		</tr>
		<tr>
			<td align="right">用户密码：</td>
			<td><input type="password" name="userPassword" id="userPassword"
				onfocus="userPassword();" size="19" /> <span class="warns"
				id="userPasswordS1">用户密码不能为空</span></td>
		</tr>
		<tr>
			<td align="right">确认密码：</td>
			<td><input type="password" name="rnewPassword" id="rnewPassword"
				onfocus="rnewPassword();" size="19" /> <span class="warns"
				id="rnewPasswordS1">两次密码不一致，请检查</span></td>
		</tr>
		<tr>
			<td align="right">用户邮箱：</td>
			<td><input type="text" name="email" id="email" size="18"
				onfocus="email();" /> <span class="warns" id="emailS1">用户邮箱不能为空</span>
				<span class="warns" id="emailS2">用户邮箱格式不对</span></td>
		</tr>
		<tr>
			<td align="right">用户电话：</td>
			<td><input type="text" name="telephone" id="telephone" size="18"
				onfocus="telephone();" /> <span class="warns" id="telephoneS1">用户电话不能为空</span>
				<span class="warns" id="telephoneS2">用户电话必须是数字串</span></td>
		</tr>
		<tr>
			<td align="right">证件号码：</td>
			<td><input type="text" name="papersNum" id="papersNum" size="18"
				onfocus="papersNum();" /> <span class="warns" id="papersNumS1">证件号码不能为空</span>
				<span class="warns" id="papersNumS2">证件号码必须是数字串</span></td>
		</tr>
		<tr>
			<td align="right">注册身份：</td>
			<td><input type="radio" name="userStatus" id="student"
				value="读者" checked="checked" onfocus="userStatus();" /> 读者 <input
				type="radio" name="userStatus" id="teacher" value="图书管理员"
				onfocus="userStatus();" /> 图书管理员</td>
		</tr>
		<tr>
			<td colspan="2" align="center" valign="middle" height="30"><input
				type="submit" name="register" id="register" value="注册" />&nbsp;&nbsp;
				<input type="button" name="back" id="back" value="返回" /></td>
		</tr>
	</table>
</body>
</html>
